package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.view.View;

import com.applozic.mobicomkit.contact.AppContactService;
import com.lottery.ruok.lottrey.retrofitModule.response.GetRoomUsersResponse;
import com.lottery.ruok.lottrey.ui.component.ChannelItemView;

import java.util.List;

/**
 * Created by ASUS on 2017/9/18.
 */

public class PrizePeopleAdapter extends BaseListAdapter<GetRoomUsersResponse.ListBean> {

    private AppContactService appContactService;

    public PrizePeopleAdapter(Context context) {
        super(context);
    }

    public PrizePeopleAdapter(Context context, List<GetRoomUsersResponse.ListBean> list) {
        super(context, list);
        this.appContactService = new AppContactService(mContext);

    }


    @Override
    protected View createItemView(Context mContext) {
        return new ChannelItemView(mContext);
    }

    @Override
    protected void onBindView(View itemView, int position) {
        if (itemView instanceof ChannelItemView) {
            ChannelItemView view = (ChannelItemView) itemView;
            view.setAppContactService(appContactService);
            view.setData(getList().get(position), getTitle(position));
        }
    }

    private String getTitle(int position) {
        String result = null;
        if (position == 0) {
            int dataType = getList().get(position).getDataType();
            switch (dataType) {
                case 0:
                    result = "用户列表";
                    break;
                case 1:
                    result = "聊天记录";
                    break;
                case 2:
                    result = "搜索记录";
                    break;
            }
            return result;
        }

        GetRoomUsersResponse.ListBean current = getList().get(position);
        GetRoomUsersResponse.ListBean last = getList().get(position - 1);
        if (current.getDataType() != last.getDataType()) {
            int dataType = current.getDataType();
            switch (dataType) {
                case 0:
                    result = "用户列表";
                    break;
                case 1:
                    result = "聊天记录";
                    break;
                case 2:
                    result = "搜索记录";
                    break;
            }
            return result;
        }
        return null;
    }
}
